package com.wang.tasker.plug.net.ftp;

import java.util.List;

import org.dom4j.Element;

import com.wang.tasker.core.ConfigElement;
import com.wang.tasker.core.Task;
import com.wang.tasker.utils.FTPHelper;

public class FTPTask extends Task {
	
	private FTPConnection conn;
	
	private String option;
	
	private String localPath;
	
	private String RemotePath;
	
	private FTPHelper helper;
	
	public FTPTask(){
		helper = new FTPHelper();
	}
	

	public void doWork() {
		helper = new FTPHelper();
		try {
			helper.setClient(this.conn.getClient());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		helper.download(this.RemotePath, this.localPath);
	}
	

	public void load(ConfigElement taskEle) {
		conn = new FTPConnection(this);
		conn.init(taskEle);
		
		ConfigElement propEle = taskEle.selectSingleElement("Properties");
		this.option = propEle.attributeValue("type");
		List subEles = propEle.elements();
		for(Object objEle:subEles){
			ConfigElement ele = (ConfigElement)objEle;
			String eleName = ele.getName();
			if("LocalPath".equals(eleName)){
				this.localPath = ele.getTextTrim();
			} else if("RemotePath".equals(eleName)){
				this.RemotePath = ele.getTextTrim();
			}
		}
	}

	public String getOption() {
		return option;
	}


	public String getLocalPath() {
		return localPath;
	}


	public String getRemotePath() {
		return RemotePath;
	}

	
	

}
